<form id="settings-form" class="form-horizontal" method="POST" action="/ru/settings/submit">


  <div class="control-group">
    <label class="" for="inputWarning">Имя</label>
    {{ user_form.username }}
    <span class="help-block"></span>
  </div>

  <div class="control-group">
    <label class="" for="inputWarning">Email работодателя (один или несколько через запятую)</label>
    {{ settings_form.employer_emails }}
    <span class="help-block"></span>
  </div>

  
  <div class="row-fluid">
    <div class="span6">
      <div class="control-group">
        <label class="" for="inputWarning">Заголовок письма о приходе</label>
        {{ settings_form.come_title }}
        <span class="help-block"></span>
      </div>
      <div class="control-group">
        <label class="" for="inputWarning">Содержание</label>
        {{ settings_form.come_text }}
        <span class="help-block"></span>
      </div>
    </div>

    <div class="span6">
      <div class="control-group">
        <label class="" for="inputWarning">Заголовок письма об уходе</label>
        {{ settings_form.gone_title }}
        <span class="help-block"></span>
      </div>
      <div class="control-group">
        <label class="" for="inputWarning">Содержание</label>
        {{ settings_form.gone_text }}
        <span class="help-block"></span>
      </div>
    </div>
  </div>




  {% if k_id %}
  <input type="hidden" name="_id" value="{{k_id}}">
  <input type="hidden" name="_token" value="{{token}}">
  {% endif %}
  <input class="submit btn btn-primary" type="submit" value="Сохранить" data-proc-val="Сохранение...">
</form>

<script>
  $(function() {
    $('#settings-form').submit(function(){
      var $form = $(this);
      var $submit = $form.find('.submit');
      var submit_val = $submit.val();
      $submit.attr('disabled', true).val($submit.attr('data-proc-val'));

      $.post($form.attr('action'), $form.serialize(), function(data) {

        if (typeof data.success != 'undefined') {

          //clear errors
          $form.find('.control-group').removeClass('error');
          $form.find('.help-block').empty();
          //show message
          messages_clear();
          success(data.success);
        } else {
          //show error-message
          messages_clear();
          error(data.error);

          //show errors
          if (data.data) {
            $.each(data.data, function(i,e){
              $form.find('[name$='+i+']').next().html(e).parents('.control-group').addClass('error');
            });
          }
        }
        $submit.attr('disabled', false).val(submit_val);
      });
        
      return false;
    });
  })
</script>